from datetime import datetime

from sqlalchemy import String, ForeignKey, DateTime, func, Enum
from sqlalchemy.orm import mapped_column, Mapped
from app.web.models.BaseModel import Base, ReportStatus


class Recruiter(Base):
    __tablename__ = "recruiter"
    name: Mapped[str] = mapped_column(String(30))
    company: Mapped[str] = mapped_column(String(50))

    def __repr__(self) -> str:
        return f"User(id={self.id!r}, company={self.company!r}"


class JobPost(Base):
    __tablename__ = "job_post"
    recruiter_id: Mapped[int] = mapped_column(ForeignKey("recruiter.id"))
    title: Mapped[str] = mapped_column(String(30))
    company: Mapped[str] = mapped_column(String(30))
    location: Mapped[str] = mapped_column(String(50))
    salary: Mapped[str] = mapped_column(String(30))
    description: Mapped[str] = mapped_column(String(500))
    requirements: Mapped[str] = mapped_column(String(100))
    publish_date: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())

    def __repr__(self) -> str:
        return f"User(id={self.id!r}, title={self.title!r}, requirements={self.requirements!r}"


class JobPostResume(Base):
    __tablename__ = "job_post_resume"
    job_post: Mapped[int] = mapped_column(ForeignKey("job_post.id"))
    resume: Mapped[int] = mapped_column(ForeignKey("resume.id"))


class ResumeReport(Base):
    __tablename__ = "resume_report"
    job_post_resume: Mapped[int] = mapped_column(ForeignKey("job_post_resume.id"))
    match_rate: Mapped[float] = mapped_column(default=-1)
    description: Mapped[str] = mapped_column(String(1000), nullable=True)
    created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
    status: Mapped[int] = mapped_column(Enum(ReportStatus), default=ReportStatus.UNEXECUTED)

